package com.cqjtu.eecs.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cqjtu.eecs.entity.*;
import com.cqjtu.eecs.entity.dto.MajorDTO;
import com.cqjtu.eecs.entity.dto.Major_Academy_Dto;
import com.cqjtu.eecs.entity.dto.StudentDTO;
import com.cqjtu.eecs.entity.params.user.UserParams;
import com.cqjtu.eecs.entity.vo.MajorVO;
import com.cqjtu.eecs.entity.vo.NaturalClassVo2;
import com.cqjtu.eecs.entity.vo.StudentVO;
import com.cqjtu.eecs.entity.vo.StudentVO2;
import com.cqjtu.eecs.service.*;
import com.cqjtu.eecs.utils.ExcelUtils;
import com.cqjtu.eecs.utils.MapUtils;
import com.cqjtu.eecs.utils.Result;
import com.cqjtu.eecs.utils.ResultCode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;

import java.util.*;
import java.util.function.Predicate;
import java.util.stream.Collectors;

/**
 * <p>
 * 学生 前端控制器
 * </p>
 *
 * @author    
 * @since 2022-03-07
 */
@RestController
@RequestMapping("/student")
@Api(tags = "学生管理模块")
public class StudentController {
    @Autowired
    private IEntryYearService iEntryYearService;
    @Autowired
    private IAcademyService iAcademyService;
    @Autowired
    private RestTemplate restTemplate;
    @Autowired
    private ObjectMapper objectMapper;
    @Autowired
    private INaturalClassService iNaturalClassService;
    @Autowired
    private IUserService iUserService;
    @Autowired
    private IStudentService iStudentService;
    @Autowired
    private IMajorService iMajorService;
    @Autowired
    private MapUtils mapMajorUtils;
    @Autowired
    private IRoleUserService iRoleUserService;

    @PostMapping("/uploadStudentByExcel")
    @ApiOperation("根据excel批量上传学生信息")
    @Transactional
    public Result uploadStudentByExcel( MultipartFile file) throws Exception {
        if(file==null) return Result.error(-1,"请不要上传空文件。");
        List<List<Object>> data = ExcelUtils.getCourseListByExcel(file.getInputStream(), file.getOriginalFilename());
        Set<Integer> yearSet=new HashSet<>();
        for (int i=0;i<data.size();i++){
            yearSet.add(Integer.valueOf(data.get(i).get(0).toString().substring(0,data.get(i).get(0).toString().indexOf("."))));
        }
        List<EntryYear> list1 = iEntryYearService.list();
        for (int i=0;i<list1.size();i++){
            yearSet.add(list1.get(i).getGrade());
        }

        for (int i=0;i<list1.size();i++){
            boolean remove = yearSet.remove(list1.get(i).getGrade());
            if(remove){
                System.out.println("删除"+list1.get(i)+"年成功");
            }
        }
        if(yearSet.size()!=0){
            //增加年级表
            for (Integer t:yearSet){
                iEntryYearService.save(new EntryYear(t));
            }
        }

        //查询学院到专业的映射,key为专业名称，value为：学院id和专业代码的dto
        Map<String, Major_Academy_Dto> map=new HashMap<>();
//        List forObject = restTemplate.getForObject("http://localhost:9090/major/majorList", List.class);
//        List<MajorVO> majorVOS = objectMapper.convertValue(forObject, new TypeReference<List<MajorVO>>() {
//        });
        List<MajorDTO> majorDTOList = iMajorService.getMajorList();
        List<MajorVO> majorVOS = new ArrayList<>();
        majorDTOList.forEach(item -> {
            MajorVO majorVO = new MajorVO();
            BeanUtils.copyProperties(item, majorVO);
            majorVOS.add(majorVO);
        });
        System.out.println(majorVOS.size()+"-------------------------------");
        for (int i=0;i<majorVOS.size();i++){
            map.put(majorVOS.get(i).getMajorName(),new Major_Academy_Dto(majorVOS.get(i).getMajorCode(),majorVOS.get(i).getAcademyId()));
        }
        //创建班级表
        List<NaturalClass> naturalClasses=new ArrayList<>();
        for (int i=0;i<data.size();i++){
            String majorName = data.get(i).get(1).toString();
            String majorCode = map.get(majorName).getMajorCode();
            Integer grade=Integer.valueOf(data.get(i).get(0).toString().substring(0,data.get(i).get(0).toString().indexOf(".")));
            String naturalClassName=data.get(i).get(2).toString();
            naturalClasses.add(new NaturalClass(majorCode,0,grade,naturalClassName));
        }
        //数据库中的班级表合并
        List<NaturalClass> naturalClasses1 = iNaturalClassService.selectAllNaturalClass();
        for (int i=0;i<naturalClasses1.size();i++){
            naturalClasses.add(naturalClasses1.get(i));
        }
        //去除重复班级
        Set<NaturalClass> naturalClassesSets=new HashSet<>();
        for (int i=0;i<naturalClasses.size();i++){
            naturalClassesSets.add(naturalClasses.get(i));
        }
        //删除和数据库重复的班级

        for (int i=0;i<naturalClasses1.size();i++){
            naturalClassesSets.remove(naturalClasses1.get(i));
        }

        //录入数据库
        for (NaturalClass t:naturalClassesSets){
            iNaturalClassService.save(t);
        }
        //录入到用户表，角色表
        List<String> roleNames=new ArrayList<>();
        roleNames.add("student");
        for (int i=0;i<data.size();i++){
            iUserService.saveUser(new UserParams(data.get(i).get(3).toString(),"123456",roleNames));
        }
        //根据学号找到用户编号,key为用户名（学号），value为uid
        List<User> list = iUserService.list();
        Map<String,Integer> mapUser=new HashMap<>();
        for (int i=0;i<list.size();i++){
            mapUser.put(list.get(i).getUsername(),list.get(i).getUid());
        }
        //根据班级名称，找到班级编号
        List<NaturalClass> naturalClasses2 = iNaturalClassService.selectAllNaturalClass();
        Map<String,Integer> mapNaturalClass=new HashMap<>();
        for (int i=0;i<naturalClasses2.size();i++){
            mapNaturalClass.put(naturalClasses2.get(i).getNaturalClassName(),naturalClasses2.get(i).getNcId());
        }
        //录入到学生表
        for (int i=0;i<data.size();i++){
            Integer grade=Integer.valueOf(data.get(i).get(0).toString().substring(0,data.get(i).get(0).toString().indexOf(".")));
            String majorName = data.get(i).get(1).toString();
            String majorCode = map.get(majorName).getMajorCode();
            Integer uid=mapUser.get(data.get(i).get(3).toString());
            Integer ncid=mapNaturalClass.get(data.get(i).get(2).toString());
            String stuCode=data.get(i).get(3).toString();
            String stuName=data.get(i).get(4).toString();
            iStudentService.save(new Student(0,grade,majorCode,ncid,uid,stuCode,stuName));
        }
        return Result.success(ResultCode.SUCCESS,"批量导入学生信息成功！！");
    }

    @PostMapping("/addStudent")
    @ApiOperation(value = "增加一个学生",notes = "不传学生的sid")
    @Transactional
    public Result addStudent(@RequestBody StudentDTO studentDTO){
        //增添用户
        List<String> roleNames=new ArrayList<>();
        roleNames.add("student");
        boolean b = iUserService.saveUser(new UserParams(studentDTO.getStuCode(), "123456", roleNames));
        if(!b) return Result.error(-1,"该学生用户已存在");
        EntryYear entryYear = iEntryYearService.getBaseMapper().selectById(studentDTO.getGrade());
        if(entryYear==null) return Result.error(-1,"年份不存在");
        Major major = iMajorService.getBaseMapper().selectById(studentDTO.getMajorCode());
        if(major==null) return Result.error(-1,"专业不存在");
        NaturalClass naturalClass=new NaturalClass(studentDTO.getMajorCode(),null,studentDTO.getGrade(),studentDTO.getNaturalClassName());
        List<NaturalClass> list = iNaturalClassService.list();
        boolean flag=false;
        Integer ncId=0;
        for (int i=0;i<list.size();i++){
            if(naturalClass.equals(list.get(i))){
                flag=true;
                ncId=list.get(i).getNcId();
                break;
            }
        }
        if(!flag) return Result.error(-1,"班级不存在");
        User user = iUserService.selectUserByStudentCode(studentDTO.getStuCode());
        Student result=new Student(null,studentDTO.getGrade(),studentDTO.getMajorCode(),ncId,user.getUid(),studentDTO.getStuCode(),studentDTO.getStuName());
        boolean save = iStudentService.save(result);
        if(!save) Result.error();
        return Result.success();
    }

    @PutMapping("/operationStudent")
    @ApiOperation(value = "学生转班，换专业，降级,改姓名等",notes = "会根据学生的学号进行对应的操作")
    @Transactional
    public Result operationStudent(@RequestBody StudentDTO studentDTO){
        Student student = iStudentService.selectStudentByStuCode(studentDTO.getStuCode());
        Map<Integer, String> mapNaturalClassUtil = mapMajorUtils.getNaturalClassUtil();
        Set<Integer> set = mapNaturalClassUtil.keySet();
        //新的班级编号
        Integer ncId_new=-1;
        for (Integer s:set){
            if(mapNaturalClassUtil.get(s).equals(studentDTO.getNaturalClassName())){
                ncId_new=s;
                break;
            }
        }
        if(ncId_new.equals(-1)) return Result.error(-1,"没有这个新的班级");
        //判断年份是否存在
        boolean year=false;
        List<EntryYear> list = iEntryYearService.list();
        for (int i=0;i<list.size();i++){
            if(list.get(i).getGrade().equals(studentDTO.getGrade())){
                year=true;
                break;
            }
        }
        if(!year) return Result.error(-1,"年份不存在");
        //查看新的专业代码是否存在
        Major major = iMajorService.getBaseMapper().selectById(studentDTO.getMajorCode());
        if(major==null) return Result.error(-1,"新的班级不存在");
        //修改学生信息
        int i = iStudentService.getBaseMapper().updateById(new Student(student.getSid(), studentDTO.getGrade(), studentDTO.getMajorCode(), ncId_new, student.getUid(), studentDTO.getStuCode(), studentDTO.getStuName()));
        if(i==1) return  Result.success();
        return Result.error();
    }

    @GetMapping("/selectStudentBySid/{sid}")
    @ApiOperation("根据学生的sid查询学生")
    public Result selectStudentBySid(@PathVariable("sid") Integer sid){
        Map<Integer, String> naturalClassUtil = mapMajorUtils.getNaturalClassUtil();
        Student student = iStudentService.getBaseMapper().selectById(sid);
        if(student==null) return Result.error(-1,"该sid查询不到学生");
        Map<String, String> mapMajorUtilsMapMajorUtil = mapMajorUtils.getMapMajorUtil();
        Map<String, String> majorCodeAcademyNameUtil = mapMajorUtils.getMajorCodeAcademyNameUtil();
        StudentDTO studentDTO=new StudentDTO(student.getGrade(),majorCodeAcademyNameUtil.get(student.getMajorCode()),student.getMajorCode(),mapMajorUtilsMapMajorUtil.get(student.getMajorCode()),naturalClassUtil.get(student.getNcId()),
                student.getStuCode(),student.getStuName());
        return Result.success(studentDTO);
    }

    @GetMapping("/selectStudentByStuCode/{stuCode}")
    @ApiOperation("根据学生的学号查询学生")
    public Result selectStudentByStuCode(@PathVariable("stuCode") String stuCode){
        Student student = iStudentService.selectStudentByStuCode(stuCode);
        Map<Integer, String> naturalClassUtil = mapMajorUtils.getNaturalClassUtil();
        if(student==null) return Result.error(-1,"该学号查询不到学生");
        Map<String, String> mapMajorUtilsMapMajorUtil = mapMajorUtils.getMapMajorUtil();
        Map<String, String> majorCodeAcademyNameUtil = mapMajorUtils.getMajorCodeAcademyNameUtil();
        StudentDTO studentDTO=new StudentDTO(student.getGrade(),majorCodeAcademyNameUtil.get(student.getMajorCode()),student.getMajorCode(),mapMajorUtilsMapMajorUtil.get(student.getMajorCode()),naturalClassUtil.get(student.getNcId()),
                student.getStuCode(),student.getStuName());
        return Result.success(studentDTO);
    }
    @GetMapping("/selectSidByStuCode/{stuCode}")
    @ApiOperation("根据学生的学号查询学生sid")
    public Result selectSidByStuCode(@PathVariable("stuCode") String stuCode){
        Student student = iStudentService.selectStudentByStuCode(stuCode);
        if(student==null) return Result.error(-1,"该学号查询不到学生");
        return Result.success(student.getSid());
    }
    @DeleteMapping("/deleteStudentBySid/{sid}")
    @ApiOperation(value = "根据学生sid删除一个学生",notes = "同时也会删除这个学生对应的用户")
    @Transactional
    public Result deleteStudentBySid(@PathVariable("sid") Integer sid){
        Student student = iStudentService.getBaseMapper().selectById(sid);
        if(student==null) return Result.error(-1,"该sid不存在");
        String stuCode = student.getStuCode();
        User user = iUserService.selectUserByStudentCode(stuCode);
        if(user==null) return Result.error(-1,"异常，学生存在但用户不存在");

        int a = iRoleUserService.deleteRoleUserByUid(user.getUid());
        //删除学生
        boolean b = iStudentService.removeById(student.getSid());
        //删除对应用户
        boolean c = iUserService.removeById(user.getUid());
        if(a==1&&b&&c) Result.success();
        return Result.error();
    }

    @GetMapping("/selectStudentByYearAndMajor/{year}/{majorCode}/{currPage}/{pageSize}")
    @ApiOperation("按照年级和专业代码分页查询学生")
    public Result selectStudentByYearAndMajor(@PathVariable("year") Integer year,@PathVariable("majorCode") String majorCode,
                                              @PathVariable("currPage") Integer currPage,@PathVariable("pageSize") Integer pageSize){
        int currPage_old=currPage;
        currPage=(currPage-1)*pageSize;
        List<Student> students = iStudentService.selectStudentByYearAndMajor(year, majorCode, currPage, pageSize);
        if(students==null) return Result.error();
        Map<Integer, String> mapMajorUtilsNaturalClassUtil = mapMajorUtils.getNaturalClassUtil();
        List<StudentDTO> result=new ArrayList<>();
        Map<String, String> majorCodeAcademyNameUtil = mapMajorUtils.getMajorCodeAcademyNameUtil();
        Map<String, String> mapMajorUtilsMapMajorUtil = mapMajorUtils.getMapMajorUtil();
        for (int i=0;i<students.size();i++){
            Student temp=students.get(i);
            result.add(new StudentDTO(temp.getGrade(),majorCodeAcademyNameUtil.get(temp.getMajorCode()),temp.getMajorCode(),mapMajorUtilsMapMajorUtil.get(temp.getMajorCode()),mapMajorUtilsNaturalClassUtil.get(temp.getNcId()),temp.getStuCode(),temp.getStuName()));
        }
        StudentVO studentVO=new StudentVO(Long.valueOf(iStudentService.count()),Long.valueOf(currPage_old),Long.valueOf(pageSize),result);
        return Result.success(studentVO);
    }

    @PutMapping("/modifyStuCodeByStuCode/{stuCode_old}/{stuCode_now}")
    @ApiOperation(value = "按照学生原来的学号修改学号",notes = "也会修改这个学生对应的用户的学号")
    @Transactional
    public Result modifyStuCodeByStuCode(@PathVariable("stuCode_old") String stuCode_old,@PathVariable("stuCode_now") String stuCode_now){
        User user_old = iUserService.selectUserByStudentCode(stuCode_old);
        Student student_old = iStudentService.selectStudentByStuCode(stuCode_old);
        if(user_old==null||student_old==null) return Result.error(-1,"没有找到这个学生");
        user_old.setUsername(stuCode_now);
        student_old.setStuCode(stuCode_now);
        int a = iUserService.getBaseMapper().updateById(user_old);
        int b = iStudentService.getBaseMapper().updateById(student_old);
        if(a==1&&b==1) return Result.success(ResultCode.SUCCESS,"修改成功");
        return Result.error();
    }

    @GetMapping("/getAllStudentCount1")
    @ApiOperation(value = "查询学生人数1",notes = "grade必填，专业代码和班级名称选填")
    public Result getAllStudentByGrade(Integer grade, String majorCode,String naturalClassName, Integer currPage,Integer pageSize){
        int currPage_old=currPage;
        currPage=(currPage-1)*pageSize;
        Map<String, String> majorCodeAcademyNameUtil = mapMajorUtils.getMajorCodeAcademyNameUtil();
        if (grade==null) return Result.error(-1,"年级为空");
        if(!majorCode.equals("")&& !naturalClassName.equals("")){
            List<NaturalClass> list = iNaturalClassService.list();
            List<StudentDTO> ans=new ArrayList<>();
            NaturalClass temp=new NaturalClass(majorCode,0,grade,naturalClassName);
            Map<String, String> utilsMapMajorUtil = mapMajorUtils.getMapMajorUtil();
            Map<Integer, String> utilsNaturalClassUtil = mapMajorUtils.getNaturalClassUtil();
            List<Student> ans_temp=new ArrayList<>();
            int total=0;
            for (int i=0;i<list.size();i++){
                if(temp.equals(list.get(i))){
                    Integer ncId=list.get(i).getNcId();
                    total+=iStudentService.getAllStudentCount_sum(grade,majorCode,ncId);
                    List<Student> allStudentCount = iStudentService.getAllStudentCount(grade, majorCode, ncId, currPage, pageSize);
                    ans_temp.addAll(allStudentCount);
                }
            }
            for (int j=0;j<ans_temp.size();j++){
                Student student = ans_temp.get(j);
                ans.add(new StudentDTO(
                        student.getGrade(),
                        majorCodeAcademyNameUtil.get(temp.getMajorCode()),
                        student.getMajorCode(),
                        utilsMapMajorUtil.get(student.getMajorCode()),
                        utilsNaturalClassUtil.get(student.getNcId()),
                        student.getStuCode(),
                        student.getStuName()));

            }
            return Result.success(new StudentVO(
                    Long.valueOf(total),
                    Long.valueOf(currPage_old),
                    Long.valueOf(pageSize),
                    ans));
        }
        if(!majorCode.equals("")&&naturalClassName.equals("")){
            long total=iStudentService.getAllStudentCount_sum(grade,majorCode,null);
            List<Student> allStudentCount = iStudentService.getAllStudentCount(grade, majorCode, null, currPage, pageSize);
            List<StudentDTO> ans=new ArrayList<>();
            Map<String, String> mapMajorUtilsMapMajorUtil = mapMajorUtils.getMapMajorUtil();
            Map<Integer, String> naturalClassUtil = mapMajorUtils.getNaturalClassUtil();
            for (int i=0;i<allStudentCount.size();i++){
                Student t=allStudentCount.get(i);
                ans.add(new StudentDTO(
                        t.getGrade(),
                        majorCodeAcademyNameUtil.get(t.getMajorCode()),
                        t.getMajorCode(),
                        mapMajorUtilsMapMajorUtil.get(t.getMajorCode()),
                        naturalClassUtil.get(t.getNcId()),
                        t.getStuCode(),
                        t.getStuName()));
            }
            return Result.success(new StudentVO(total,Long.valueOf(currPage),Long.valueOf(pageSize),ans));
        }
        if(majorCode.equals("")&&naturalClassName.equals("")){
            long total=iStudentService.getAllStudentCount_sum(grade,null,null);
            List<Student> allStudentCount = iStudentService.getAllStudentCount(grade, null, null, currPage, pageSize);
            Map<String, String> mapMajorUtilsMapMajorUtil = mapMajorUtils.getMapMajorUtil();
            List<StudentDTO> ans=new ArrayList<>();
            Map<Integer, String> naturalClassUtil = mapMajorUtils.getNaturalClassUtil();
            for (int i=0;i<allStudentCount.size();i++){
                Student t=allStudentCount.get(i);
                ans.add(new StudentDTO(
                        t.getGrade(),
                        majorCodeAcademyNameUtil.get(t.getMajorCode()),
                        t.getMajorCode(),
                        mapMajorUtilsMapMajorUtil.get(t.getMajorCode()),
                        naturalClassUtil.get(t.getNcId()),
                        t.getStuCode(),
                        t.getStuName()));
            }
            return Result.success(new StudentVO(total,Long.valueOf(currPage),Long.valueOf(pageSize),ans));

        }
        return Result.error();
    }
    @GetMapping("/getAllStudentCount2")
    @ApiOperation(value = "查询学生人数2",notes = "分页查询某个年级，某个学院下有多少学生")
    public Result getAllStudentCount2(Integer grade, String academyId,Integer currPage,Integer pageSize){
        List<String> selectAllMajorCodeByAcademyId = iMajorService.selectAllMajorCodeByAcademyId(academyId);
        Map<String, String> majorCodeAcademyNameUtil = mapMajorUtils.getMajorCodeAcademyNameUtil();
        int ans=0;
        List<Student> tem=new ArrayList<>();
        for (int i=0;i<selectAllMajorCodeByAcademyId.size();i++){
            int t=iStudentService.getAllStudentCount2(grade,selectAllMajorCodeByAcademyId.get(i));
            ans+=t;
            List<Student> allStudentCount2_domain = iStudentService.getAllStudentCount2_domain(grade, selectAllMajorCodeByAcademyId.get(i));
            tem.addAll(allStudentCount2_domain);
        }
        //从第几条数据开始
        int firstIndex = (currPage - 1) * pageSize;
        //到第几条数据结束
        int lastIndex = currPage * pageSize;
        Map<String, String> mapMajorUtilsMapMajorUtil = mapMajorUtils.getMapMajorUtil();
        Map<Integer, String> naturalClassUtil = mapMajorUtils.getNaturalClassUtil();
        List<StudentDTO> studentDTOS=new ArrayList<>();
        for (int i=0;i<tem.size();i++){
            studentDTOS.add(new StudentDTO(
                    grade,
                    majorCodeAcademyNameUtil.get(tem.get(i).getMajorCode()),
                    tem.get(i).getMajorCode(),
                    mapMajorUtilsMapMajorUtil.get(tem.get(i).getMajorCode()),
                    naturalClassUtil.get(tem.get(i).getNcId()),
                    tem.get(i).getStuCode(),
                    tem.get(i).getStuName()));
        }
        try {
            return Result.success(new StudentVO(Long.valueOf(ans),Long.valueOf(currPage),Long.valueOf(pageSize), studentDTOS.subList(firstIndex,lastIndex)));
        }catch (Exception e){
            if(pageSize>studentDTOS.size()){
                return Result.success(new StudentVO(Long.valueOf(ans),Long.valueOf(currPage),Long.valueOf(pageSize),studentDTOS.subList(0,studentDTOS.size())));
            }
            if(currPage*pageSize>studentDTOS.size()&&pageSize>studentDTOS.size()){
                return Result.success(new StudentVO(Long.valueOf(ans),Long.valueOf(currPage),Long.valueOf(pageSize),studentDTOS.subList(firstIndex,studentDTOS.size())));
            }
            return Result.success(new StudentVO(Long.valueOf(ans),Long.valueOf(currPage),Long.valueOf(pageSize),null));
        }

    }

    @DeleteMapping("/deleteStudentByStuCode/{stuCode}")
    @ApiOperation(value = "根据学号删除学生",notes = "也会删除用户")
    @Transactional
    public Result deleteStudentByStuCode(@PathVariable String stuCode){
        Student student = iStudentService.selectStudentByStuCode(stuCode);
        User user = iUserService.selectUserByStudentCode(stuCode);
        if(student==null||user==null) return Result.error();
        int a = iRoleUserService.deleteRoleUserByUid(user.getUid());
        int b = iStudentService.getBaseMapper().deleteById(student.getSid());
        int c = iUserService.getBaseMapper().deleteById(user.getUid());
        if(a==1&&b==1&&c==1) return Result.success();
        return Result.error();
    }
    @GetMapping("/queryStudentByClassID/{nc_id}")
    @ApiOperation(value = "根据自然班编号返回学生的姓名和学号")
    public Result<List<StudentVO2>> queryStudentByClassID(@PathVariable("nc_id") Integer ncId){
        Map<String, Object> map=new HashMap<>();
        map.put("nc_id",ncId);
        List<Student> students = iStudentService.getBaseMapper().selectByMap(map);
        if(students.size()==0){
            return Result.error(-1,"该班级没有学生，检查班级编号");
        }
        List<StudentVO2> res = students.stream().map(s -> new StudentVO2(s.getStuCode(), s.getStuName())).collect(Collectors.toList());
        return Result.success(res);
    }
}
